# -*- coding: utf-8 -*
import os

#定义count为全局变量，初始值为0
sum = 0


def count_path(dir1):
    #获取目录中的所有文件信息
    dlist = os.listdir(dir1)
    global sum
    for f in dlist:
        file1 = os.path.join(dir1,f)
        if os.path.isfile(file1):
            sum += os.path.getsize(file1)
        if os.path.isdir(file1):
            count_path(file1)
dir_Name = './test'
count_path(dir_Name)
print('{}文件夹大小共{}KB'.format(dir_Name,sum//1024))